package qeb.handheldmedical.adapter;

import java.util.List;

import qeb.handheldmedical.R;
import qeb.handheldmedical.model.ExamChoose;
import qeb.handheldmedical.model.ExamItem;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;

/**
 * @author 作者(dugaoyi) E-mail:dugaoyi@163.com
 * @version 创建时间：2016年8月30日 下午3:58:42
 * @declaration 试题答应Checkbox
 */
public class ExamItemAdapter extends BaseAdapter {

	private static final String TAG = "mExamItem";
	// private ImageSwitcher mImageLoader;
	private int mCount;
	private Context mContext;
	private ExamItem mExamItem = null;

	public ExamItemAdapter(int count, Context context, ExamItem examItem) {
		this.mCount = count;
		this.mContext = context;
		this.mExamItem = examItem;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mCount;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewholder = null;
		convertView = LayoutInflater.from(mContext).inflate(
				R.layout.adapter_exam_item, null);
		viewholder = new ViewHolder();
		viewholder.examchk = (CheckBox) convertView.findViewById(R.id.examchk);
		convertView.setTag(viewholder);

		try {
			ExamChoose examChoose = mExamItem.getChooses().get(position);
			viewholder.examchk.setText(examChoose.getItemName());
			if (null != mExamItem.getChooseValue()
					&& mExamItem.getChooses().size() > 0) {
				for (int i = 0; i < mExamItem.getChooseValue().size(); i++) {
					if ((position + 1) == mExamItem.getChooseValue().get(i)) {
						viewholder.examchk.setChecked(true);
					}
				}
			}

		} catch (Exception e) {
			// TODO: handle exception
			Log.e(TAG, e.toString());
		}
		return convertView;

	}

	static class ViewHolder {
		CheckBox examchk;
	}
}
